package com.ruoyi.project.manhua.webLook.service.impl;


import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.framework.qiniu.QiNiuYunUtils;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.manhua.name.domain.MhName;
import com.ruoyi.project.manhua.newXml.MhNameNewMapper;
import com.ruoyi.project.manhua.webLook.entity.MhWebName;
import com.ruoyi.project.manhua.webLook.service.MhSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.List;


@Service
public class MhSearchServiceImpl implements MhSearchService {


    @Autowired
    private MhNameNewMapper mhNameNewMapper;

    @Autowired
    private QiNiuYunUtils qiNiuYunUtils;


    /**
     * 模糊查询 用于 搜索页面 搜索框 动态查询
     *
     * @return
     */
    @Override
    public List<String> searchServiceName() {
        return mhNameNewMapper.selectSearchInput();
    }

    /**
     * 模糊查询
     *
     * @param name
     * @return
     */
    @Override
    public AjaxResult searchSerivceLike(String name) {

        AjaxResult ajaxResult = new AjaxResult();

        MhWebName mhWebName = new MhWebName();

        mhWebName.setName(name);

        mhWebName.setState("");

        List<MhName> mhNames = mhNameNewMapper.seletWebLimitList(mhWebName);

        mhNames.forEach((e) -> {
            e.setTheCover(Constants.getEncoder(qiNiuYunUtils.getUrlImg(e.getTheCover())));
        });

        ajaxResult.put("lists", mhNames);

        if (!ObjectUtils.isEmpty(ShiroUtils.getSysUser())) {
            ajaxResult.put("avatar", ShiroUtils.getSysUser().getAvatar());

        }

        return ajaxResult;
    }
}
